package com.xmsx.back.service.index;

import com.xmsx.back.mapper.index.RecruitmentMapper;
import com.xmsx.back.pojo.Recruitment;
import com.xmsx.back.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RecruitmentService {

    @Autowired
    RecruitmentMapper recruitmentMapper;

    public List<String> getTagList() {
        return recruitmentMapper.getTagList();
    }

    /**
     * 按tag分页查找多条数据
     *
     * @param page
     * @param size
     * @param tag
     * @return
     */
    public Pager<Recruitment> findByTagByPager(int page, int size, String tag) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page - 1) * size);
        params.put("size", size);
        params.put("tag", tag);
        Pager<Recruitment> pager = new Pager<Recruitment>();
        List<Recruitment> list = recruitmentMapper.findByTagByPager(params);
        pager.setRows(list);
        pager.setTotal(recruitmentMapper.countByTag(tag));
        return pager;
    }

    public Pager<Recruitment> findByKeywordByPager(int page, int size, String keyword) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page - 1) * size);
        params.put("size", size);
        params.put("keyword", keyword);
        Pager<Recruitment> pager = new Pager<Recruitment>();
        List<Recruitment> list = recruitmentMapper.findByKeywordByPager(params);
        pager.setRows(list);
        pager.setTotal(recruitmentMapper.countByKeyword(keyword));
        return pager;
    }

    /**
     * 分页查找多条数据
     *
     * @param page
     * @param size
     * @return
     */
    public Pager<Recruitment> findByTagByPager(int page, int size) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page - 1) * size);
        params.put("size", size);
        Pager<Recruitment> pager = new Pager<Recruitment>();
        List<Recruitment> list = recruitmentMapper.findByPager(params);
        pager.setRows(list);
        pager.setTotal(recruitmentMapper.count());
        return pager;
    }
}
